tz.py 618 B

123456789101112131415161718192021
  1. from datetime import tzinfo, timedelta
  2. class TomlTz(tzinfo):
  3. def __init__(self, toml_offset):
  4. if toml_offset == "Z":
  5. self._raw_offset = "+00:00"
  6. else:
  7. self._raw_offset = toml_offset
  8. self._sign = -1 if self._raw_offset[0] == '-' else 1
  9. self._hours = int(self._raw_offset[1:3])
  10. self._minutes = int(self._raw_offset[4:6])
  11. def tzname(self, dt):
  12. return "UTC" + self._raw_offset
  13. def utcoffset(self, dt):
  14. return self._sign * timedelta(hours=self._hours, minutes=self._minutes)
  15. def dst(self, dt):
  16. return timedelta(0)